package com.hc.Controller;


import com.hc.pojo.Meber;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
public class MemberCoontroller {

    @RequestMapping("/getMenber")
    public String getMenber(){
        return "尊贵的劳斯莱斯的车主：何金涛【9101】";
    }

    @RequestMapping("/getMenberById")
    public  String getMenberById(Integer id){

        return "尊贵的劳斯莱斯的车主:"+id;
    }

    /**
     * 根据id查询会员信息，服务熔断的演示方法
     * @param id
     * @return
     */

    @RequestMapping("/getMenberById2")
    @HystrixCommand(fallbackMethod = "processHystrix")
    public  Meber getMenberById2(Integer id){
        if (id==0){
            throw new RuntimeException("该"+id+"存在异常！！！");
        }
        return new Meber(id,"涛车主");
    }


    public  Meber processHystrix(Integer id){

        return new Meber(-1,"当前系统出现问题,请联系管理员。");
    }

    @RequestMapping("/addMeber")
    public void addMeber(@RequestBody Meber meber){
        System.out.println("_****************************");
        System.out.println(meber);
        System.out.println("_****************************");
    }



    @RequestMapping("/getMenberList")
    public List<Meber> getMenberList(){
        List<Meber> list=new ArrayList<>();

        list.add(new Meber(1,"李小"));
        list.add(new Meber(2,"李红"));
        list.add(new Meber(3,"李白"));
        list.add(new Meber(4,"阿布"));
        return list;
    }





}
